<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$appConfigs.title}</title>

    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/{$page_theme | default: 'default'}/easyui.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/style/my.css">
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/javascript/my.js"></script>
    
</head> 
<body onpageshow="resetPagination('dg')">
    {datagrid id="dg" datasource="/invest/InvestmentTransactionService/findAll.do" view="i_investment_transaction"}
    {form id="dlg" template="common/form2.tpl" view="i_investment_transaction" }
    {form id="dlg2" template="common/form2.tpl" view="i_investment_transaction_finish" }
    {form id="dlg3" template="common/form.tpl"  view="i_investment_transaction_append" }
    
    <script>
	var invest_id ={$Request.invest_id};
    {literal}
	var objectives = {0:"无", 1:"长期-观察仓", 2:"长期-底仓", 3:"中期-观察仓", 4:"长期-临时加仓", 5:"长期-价值平均买", 6:"长期-价值平均卖",
			7:"中期-网格交易买",8:"中期-网格交易卖",9:"长期-减仓",10:"长期-清仓",11:"其它交易",12:"中期-趋势交易买",13:"中期-趋势交易卖"};
	var term_type = {0:"无", 1:"短线", 2:"中线", 3:"长线", 4:"长线底仓"};
    field_formatters.status=function (value, row, index){
		if(value == 0)
			return '交易中';
		else if(value == 1)
			return "<font color='green'>交易成功</font>";
		else if(value == 2)
			return "<font color='red'>交易失败</font>";
    }
    field_formatters.transaction_type=function (value, row, index){
		if(value == 1)
			return "<font color='blue'>买入</font>";
		else if(value == -1)
			return "<font color='green'>卖出</font>";
    }
    field_formatters.transaction_date=function (value, row, index){
		if(value)
			return value.substring(0, 10);
    }
    field_formatters.transaction_method=function (value, row, index){
		if(value == 0)
			return "<font color='red'>随性交易</font>";
		else if(value == 1)
			return "<font color='blue'>手动交易</font>";
		else if(value == 2)
			return "<font color='green'>策略交易</font>";
		else
			return value;
    }
    field_formatters.objective=function (value, row, index){
		if(value) {
			if(objectives[value])
				return objectives[value];
			else
				return value;
		}
    }
    field_formatters.term_type=function (value, row, index){
		if(value && term_type[value]){
			return term_type[value];
		} else {
			return value;
		}
    }
	action_prehandlers.createOne = function() {
		const timeElapsed = Date.now();
		const today = new Date(timeElapsed);
		return {"invest_id":invest_id, "transaction_date": date_formatter(today)};
	}
    function finishTransaction() {
    	updateOne("dlg2","/invest/InvestmentTransactionService/finishTransaction.do","dg",{"status":1})
    }
    function appendTransaction() {
    	updateOne("dlg3","/invest/InvestmentTransactionService/appendTransaction.do","dg",{"status":1})
    }
    {/literal}
    </script>
</body>
</html>